import base from "./base";

export default (url, method = "GET", data = {}, options={}) => {
	return new Promise((resolve, reject) => {

		if (options.loading) {
			uni.showLoading({
				title: "请求成功"
			})
		}
		uni.request({
			url: base.host + url,
			data,
			method,
			success: (res) => {
				if (res.data.status === 200) {
					uni.showToast({
						title: "请求成功"
					})
				}
				//返回数据
				resolve(res.data);
			},
			fail: (reason) => {
				uni.showToast({
					title: "请求失败"
				})
				//返回错误原因并执行catch
				reject(reason);
			},
			complete() {

			}
		})
	})
}